﻿using Application.DictDataService;
using Domain.Entity;
using Domain.Entity.sys;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WMSManage.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DictDataController : ControllerBase
    {
        private readonly IDictDataService dictDataService;

        public DictDataController(IDictDataService dictDataService)
        {
            this.dictDataService = dictDataService;
        }


        /// <summary>
        /// 根据字典类型分页查询数据
        /// </summary>
        /// <param name="label">标签</param>
        /// <param name="status">状态</param>
        /// <param name="createname">创建人</param>
        /// <param name="starttime">开始时间</param>
        /// <param name="endtime">结束时间</param>
        /// <param name="typeid">字典类型ID</param>
        /// <param name="CurrentPage">当前页</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<FenYe<DictData>> GetDictDataByType(string? label, int? status, string? createname, string? starttime, string? endtime, int typeid, int CurrentPage)
        {
            FenYe<DictData> fenYe = new FenYe<DictData>()
            {
                CurrentPage = CurrentPage,
            };
            return await dictDataService.GetDictDataByType(fenYe, label, status, createname, starttime, endtime, typeid);
        }


        /// <summary>
        /// 添加字典数据
        /// </summary>
        /// <param name="addDictDataDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddDictData(AddDictDataDto addDictDataDto)
        {
            return await dictDataService.AddDictData(addDictDataDto);
        }


        /// <summary>
        /// 删除字典数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> DeleteDictData(int id)
        {
            return await dictDataService.DeleteDictData(id);
        }


        /// <summary>
        /// 根据id查询字典数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<DictData> GetDictDataById(int id)
        {
            return await dictDataService.GetDictDataById(id);
        }


        /// <summary>
        /// 修改字典数据
        /// </summary>
        /// <param name="updateDictDataDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> UpdateDictData(UpdateDictDataDto updateDictDataDto)
        {
            return await dictDataService.UpdateDictData(updateDictDataDto);
        }


        /// <summary>
        /// 根据字典类型查询数据
        /// </summary>
        /// <param name="typeid">字典类型id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<DictData>> GetAllDictDataBytype(int typeid)
        {
            return await dictDataService.GetAllDictDataBytype(typeid);
        }
    }
}
